package com.shum1n.gmall.user.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.shum1n.gmall.bean.UserInfo;
import com.shum1n.gmall.service.UserService;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@RestController
public class UserController {

    @Reference
    UserService userService;

    /**
     * http://localhost:8080/getUserById?id=1
     * @return
     */
    @GetMapping("/getUserById")
    public UserInfo getUserById(String id){
        return userService.getUserInfoById(id);
    }

    /**
     * http://localhost:8080/allusers
     * @return
     */
    @GetMapping("/allusers")
    public List<UserInfo> getAllUsers(){
        return userService.getUserInfoListAll();
    }

    /**
     * http://localhost:8080/addUser?name=zhangsan&email=123@qq.com
     * @param userInfo
     * @return
     */
    @PostMapping("/addUser")
    public String addUser(UserInfo userInfo){
        userService.addUser(userInfo);
        return "success";
    }

    @PostMapping("/updateUser")
    public String updateUser(UserInfo userInfo){
        userService.updateUser(userInfo);
        return "success";
    }

    @PostMapping("/updateUserByName")
    public String updateUserByName(UserInfo userInfo){
        userService.updateUserByName(userInfo.getName(),userInfo);
        return "success";
    }

    @Delete("/delUser")
    public String delUser(UserInfo userInfo){
        userService.delUser(userInfo);
        return "success";
    }

}
